using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Framework;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;
using System.Data;

namespace ITCrossing
{
	public partial class itcMetaPost_EditProvider : PortalModuleBase
    {

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
			Load +=new EventHandler(Page_Load);

			// Replace the object qualifier with the right string.
        	SqlDataSource1.SelectCommand =
        		SqlDataSource1.SelectCommand.Replace("{databaseOwner}", MetaPostServices.DatabaseOwner);
			SqlDataSource1.SelectCommand =
				SqlDataSource1.SelectCommand.Replace("{objectQualifier}", MetaPostServices.ObjectQualifier);
			SqlDataSource1.UpdateCommand =
				SqlDataSource1.UpdateCommand.Replace("{databaseOwner}", MetaPostServices.DatabaseOwner);
			SqlDataSource1.UpdateCommand =
				SqlDataSource1.UpdateCommand.Replace("{objectQualifier}", MetaPostServices.ObjectQualifier);

        }

        protected void Page_Load(object sender, EventArgs e)
		{
			if (AJAX.IsInstalled())
            {
                AJAX.RegisterScriptManager();
            }
            if (!Page.IsPostBack)
			{
			}

			FormView1.ChangeMode(FormViewMode.Edit);

			ContainerControl.Visible = (UserInfo.IsSuperUser) ? true : false;
        }

		protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
		{
			if (e.CommandName == "Cancel")
			{
				Response.Redirect(Globals.NavigateURL(TabId, "ManageProviders","mid=" + ModuleId));
			}
			else if (e.CommandName == "SetDefault")
			{
				TextBox txtContentUpd = (TextBox) FormView1.FindControl("txtContentUpd");
				txtContentUpd.Text =
					"<div class=d_itc_f style=\"CLEAR: both; HEIGHT: 11px\"><script src=\"" + MetaPostServices.GetAppPath() + "/DesktopModules/itcMetaPost/js/mg.js\" type=text/javascript></script></div>";
			}
		}

		protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
		{
			Response.Redirect(Globals.NavigateURL(TabId, "ManageProviders", "mid=" + ModuleId));
		}


		protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e)
		{
			e.NewValues["FooterTemplate"] = HttpUtility.HtmlEncode(e.NewValues["FooterTemplate"].ToString());
		}

		protected void FormView1_DataBound(object sender, EventArgs e)
		{
			TextBox txtContentUpd = (TextBox)FormView1.FindControl("txtContentUpd");
			txtContentUpd.Text = HttpUtility.HtmlDecode(txtContentUpd.Text);
		}


    }
}